<template>
    <div>
        <h1>科室录入</h1>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td align="right">病床号</td>
                    <td><input type="text" v-model="info.FJH"></td>
                </tr>

                <tr>
                    <td align="right">病房名称</td>
                    <td><input type="text" v-model="info.FJHName"></td>
                </tr>

                <tr>
                    <td align="right">所属科室</td>
                    <td><select v-model="info.KSId">
                            <option value="">请选择</option>
                            <option :value="itme.Id" v-for="itme in lisr" :key="itme.Id">{{ itme.Name }}</option>
                        </select></td>
                </tr>

                <tr>
                    <td align="right">床位总数量</td>
                    <td><input type="text" v-model="info.NuMber"></td>
                </tr>


                <tr>
                    <td align="right">人数状态</td>
                    <td><input type="radio" name="sts" :value="true" v-model="info.Strte">已满
                        <input type="radio" name="sts" :value="false" v-model="info.Strte">未满
                    </td>
                </tr>

                <tr>
                    <td align="right">病房状态</td>
                    <td><input type="radio" name="st" :value="true" v-model="info.State">启用
                        <input type="radio" name="st" :value="false" v-model="info.State">维修
                    </td>
                </tr>

                <tr>
                    <td align="right">空闲床数量</td>
                    <td><input type="text" v-model="info.KX"></td>
                </tr>

                <tr>
                    <td align="right">创建日期</td>
                    <td><input type="date" v-model="info.ConTime"></td>
                </tr>

                <tr>
                    <td align="right"></td>
                    <td><input type="button" value="录入" @click="ok"></td>
                </tr>

            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue'
import axios from 'axios';
import { useRouter, useRoute } from 'vue-router';
const router = useRouter();
const route = useRoute();
let info: any = reactive({
    "FJH": "",
    "FJHName": "",
    "KSId": "",
    "NuMber": "",
    "Strte": false,
    "State": "",
    "KX": "",
    "ConTime": ""
})
let lisr: any = ref([]);
onMounted(() => {
    getlisr();
})
const ok = () => {
    if (info.FJHName == "") {
        alert("病房名称");
        return;
    }
    if (info.FJHName.length >= 6) {
        alert("不能超过6个字符");
        return;
    }
    axios({
        url: '/api/BF/BFAdd',
        method: 'post',
        data: info
    })
        .then((res) => {
            console.log(res);
            if (res.data == -1) {
                alert("病房名称重复");
                return;
            }
            if (res.data > 0) {
                alert("录入成功");
                router.push('/bfshow');
                return;
            }
            else {
                alert("录入失败");
                return;
            }
        })
        .catch((err) => {
            console.log(err);

        })
}
//===============================================
const getlisr = () => {
    axios({
        url: '/api/KS/KSShow',
        method: 'get',

    })
        .then((res) => {
            console.log(res);
            lisr.value = res.data
        })
        .catch((err) => {
            console.log(err);

        })
}
</script>

<style scoped></style>